package com.yhm.myfootbollshow.demos.service.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yhm.myfootbollshow.demos.entity.po.Category;
import com.yhm.myfootbollshow.demos.entity.vo.CategoryVo;
import com.yhm.myfootbollshow.demos.mapper.CategoryMapper;
import com.yhm.myfootbollshow.demos.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: yhm
 * @time: 2025/4/4 17:05
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    // 获取分类列表
    @Override
    public List<CategoryVo> listCategory() {
        LambdaQueryWrapper<Category> categoryLambdaQueryWrapper = new LambdaQueryWrapper<Category>();
        categoryLambdaQueryWrapper.select(Category::getCategoryId, Category::getCategoryName)
                .eq(Category::getStatus, 1)
                .orderByAsc(Category::getSort);
        List<Category> categories = list(categoryLambdaQueryWrapper);
        return categories.stream()
                .map(category -> new CategoryVo()
                        .setId(category.getCategoryId())
                        .setName(category.getCategoryName()))
                .collect(Collectors.toList());
    }
}
